home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / lib / Splayset.sig < prev    next >
Encoding:
Text File  |  1997-08-18  |  3.3 KB  |  91 lines  |  [TEXT/Moml]

  1. (* Splayset -- applicative sets implemented by splay-trees.
  2.  * 
  3.  * Modified for Moscow ML 1995-04-22 from SML/NJ lib 0.2 file ordset-sig.sml.
  4.  * COPYRIGHT (c) 1993 by AT&T Bell Laboratories.  
  5.  * See file mosml/copyrght/copyrght.att for details.
  6.  *)
  7.  
  8. type 'item set
  9.  
  10. exception NotFound
  11.  
  12. val empty        : ('_item * '_item -> order) -> '_item set
  13. val singleton    : ('_item * '_item -> order) -> '_item -> '_item set
  14. val add          : '_item set * '_item -> '_item set
  15. val addList      : '_item set * '_item list -> '_item set
  16. val retrieve     : 'item set * 'item -> 'item
  17. val peek         : 'item set * 'item -> 'item option
  18. val isEmpty      : 'item set -> bool
  19. val equal        : 'item set * 'item set -> bool
  20. val isSubset     : 'item set * 'item set -> bool
  21. val member       : 'item set * 'item -> bool
  22. val delete       : '_item set * '_item -> '_item set
  23. val numItems     : 'item set ->  int
  24. val union        : '_item set * '_item set -> '_item set
  25. val intersection : '_item set * '_item set -> '_item set
  26. val difference   : '_item set * '_item set -> '_item set
  27. val listItems    : 'item set -> 'item list
  28. val app          : ('item -> unit) -> 'item set -> unit
  29. val revapp       : ('item -> unit) -> 'item set -> unit
  30. val foldr        : ('item * 'b -> 'b) -> 'b -> 'item set -> 'b
  31. val foldl        : ('item * 'b -> 'b) -> 'b -> 'item set -> 'b
  32. val find         : ('item -> bool) -> 'item set -> 'item option
  33.  
  34. (* This unit implements sets of ordered elements.  Every set is
  35.    equipped with an ordering relation; the ordering relation is used
  36.    in the representation of the set.  The result of combining two sets
  37.    (of the same type but) with different ordering relations is undefined.
  38.    The implementation uses splay-trees (Sleator and Tarjan).
  39.  
  40.    [empty ordr] creates a new empty set with the given ordering
  41.    relation.  
  42.  
  43.    [singleton ordr i] creates the singleton set containing i, with the
  44.    given ordering relation.
  45.  
  46.    [add(s, i)] adds item i to set s.  
  47.  
  48.    [addList(s, xs)] adds all items from the list xs to the set s.
  49.  
  50.    [retrieve(s, i)] returns i if it is in s; raises NotFound otherwise.
  51.  
  52.    [peek(s, i)] returns SOME i if i is in s; returns NONE otherwise.
  53.  
  54.    [isEmpty s] returns true if and only if the set is empty.
  55.  
  56.    [equal(s1, s2)] returns true if and only if the two sets have the
  57.    same elements.
  58.  
  59.    [isSubset(s1, s2)] returns true if and only if s1 is a subset of s2.
  60.  
  61.    [member(s, i)] returns true if and only if i is in s.
  62.  
  63.    [delete(s, i)] removes item i from s.  Raises NotFound if i is not in s.
  64.    
  65.    [numItems s] returns the number of items in set s.
  66.  
  67.    [union(s1, s2)] returns the union of s1 and s2.  
  68.  
  69.    [intersection(s1, s2)] returns the intersectionof s1 and s2.
  70.  
  71.    [difference(s1, s2)] returns the difference between s1 and s2 (that
  72.    is, the set of elements in s1 but not in s2).
  73.  
  74.    [listItems s] returns a list of the items in set s.
  75.  
  76.    [app f s] applies function f to the elements of s, in increasing
  77.    order.
  78.  
  79.    [revapp f s] applies function f to the elements of s, in decreasing
  80.    order. 
  81.  
  82.    [foldl f e s] applies the folding function f to the entries of the
  83.    set in increasing order.
  84.  
  85.    [foldr f e s] applies the folding function f to the entries of the
  86.    set in decreasing order. 
  87.  
  88.    [find p s] returns SOME i, where i is an item in s which satisfies
  89.    p, if one exists; otherwise returns NONE.
  90. *)    
  91.